package com.qianf.wisdomOrientation.controller;


import com.qianf.wisdomOrientation.entity.Message;
import com.qianf.wisdomOrientation.entity.ResponseData;
import com.qianf.wisdomOrientation.entity.User;
import com.qianf.wisdomOrientation.service.MessageService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mkHeart
 * @since 2021-07-08
 */
@RestController
@RequestMapping("/wisdomOrientation/message")
public class MessageController {

    @Autowired
    private MessageService service;

    // produces = "application/json" 返回数据时json 数据
    @ApiOperation(value = "查询所有的消息", produces = "application/json")
    @RequestMapping(path = "/findAllMessage", method = RequestMethod.GET)

    public ResponseData findAllMessage() {
        ResponseData<Object> responseData = new ResponseData<>();
        List<Message> allMessage = service.findAllMessage();

        responseData.setCode(0);
        responseData.setData(allMessage);
        return responseData;
    }
    // produces = "application/json" 返回数据时json 数据
    @ApiOperation(value = "根据 id查询消息的详细信息", produces = "application/json")
    @RequestMapping(path = "/findMessageById", method = RequestMethod.GET)

    public ResponseData findMessageById(int id) {
        ResponseData<Message> responseData = new ResponseData<>();
       Message messageById = service.findMessageById(id);

        responseData.setCode(0);
        responseData.setData(messageById);
        return responseData;
    }
    // produces = "application/json" 返回数据时json 数据
    @ApiOperation(value = "根据 消息id查询回复的消息 ", produces = "application/json")
    @RequestMapping(path = "/findMessageReply", method = RequestMethod.GET)

    public ResponseData findMessageReply(int messageid) {
        ResponseData<Object> responseData = new ResponseData<>();
       List<Message> messageById = service.findMessageReply(messageid);

        responseData.setCode(0);
        responseData.setData(messageById);
        return responseData;
    }
    // produces = "application/json" 返回数据时json 数据
    @ApiOperation(value = "添加消息  ", produces = "application/json")
    @RequestMapping(path = "/addMessage", method = RequestMethod.GET)

        public ResponseData addMessage(Message message) {
        ResponseData<Object> responseData = new ResponseData<>();

        int i = service.addMessage(message);
        if (i>0){
            responseData.setCode(1);
            responseData.setMsg("添加成功");
            return responseData;
        }else {
            responseData.setCode(0);
            return responseData;
        }
    }


}

